package com.hirsi.module.auth.controller;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import com.hirsi.common.core.annotation.IgnoreAccessTokenValid;
import com.hirsi.common.core.annotation.RequestBodyParam;
import com.hirsi.module.auth.service.DeveloperAuthService;
import com.hirsi.module.auth.vo.param.RegisterAccountParam;
import com.hirsi.module.auth.vo.param.RegisterCheckPhoneParam;
import com.hirsi.module.auth.vo.param.RegisterSendSmsParam;
import com.hirsi.module.auth.vo.result.RegisterAccountDetailResult;
import com.hirsi.module.auth.vo.result.RegisterAccountSecretResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@Api(tags = "授权登录相关接口")
@ApiSupport(order = 1)
@RestController
@RequestMapping("rest/v1/auth")
public class DeveloperAuthController {

    @Autowired
    private DeveloperAuthService developerAuthService;

    @IgnoreAccessTokenValid
    @ApiOperation("开发者注册发送短信验证码")
    @ApiOperationSupport(order = 1)
    @PostMapping("send_register_sms_code")
    public void sendSmsCode(@RequestBodyParam @Validated RegisterSendSmsParam param) {
        developerAuthService.sendSmsCode(param);
    }

    @IgnoreAccessTokenValid
    @ApiOperation(value = "开发者注册验证手机号", notes = "如果状态待审核或驳回会回显")
    @ApiOperationSupport(order = 2)
    @PostMapping("check_phone")
    public RegisterAccountDetailResult checkPhone(@RequestBodyParam @Validated RegisterCheckPhoneParam param) {
        return developerAuthService.checkPhone(param);
    }

    @IgnoreAccessTokenValid
    @ApiOperation("开发者注册账号")
    @ApiOperationSupport(order = 3)
    @PostMapping("register")
    public RegisterAccountSecretResult register(@RequestBodyParam @Validated RegisterAccountParam param) {
        return developerAuthService.register(param);
    }

    @IgnoreAccessTokenValid
    @ApiOperation("获取注册账户详情")
    @ApiOperationSupport(order = 4)
    @GetMapping("register_account_detail")
    public RegisterAccountDetailResult registerAccountDetail(@ApiParam(value = "注册成功的密钥", required = true) @RequestParam String secretKey) {
        return developerAuthService.registerAccountDetail(secretKey);
    }
}
